<?php
namespace Admin\Controller;

use Think\Controller;
use Think\Crypt\Driver\Think;

class RemindDetailController extends Controller
{

    public function myTask()
    {
        sess();
        $task = M('Task');
        $count = $task->where(array(
            'juid' => array(
                'like',
                '%' . session('uid') . '%'
            )
        ))->count();
        $Page = getpage($count, 5); // 实例化分页类 传入总记录数
        $show = $Page->show(); // 分页显示输出
        $list = $task->where(array(
            'juid' => array(
                'like',
                '%' . session('uid') . '%'
            )
        ))
            ->order("id desc")
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->select();
        $this->assign('list', $list);
        // $this->assign('totalCount', $count);
        // $this->assign('currentPage', ! empty($_GET['pageNum']) ? $_GET['pageNum'] : 1);
        // $this->assign('numPerPage', $numPerPage);
        $this->assign('page', $show);
        updateTime();
        $this->display();
    }

    public function taskView()
    {
        sess();
        $task = M('Task');
        $data = $task->getByid($_GET['id']);
        $this->assign('Rs', $data);
        $this->display();
    }

    public function myCust()
    {
        sess();
        $cust = M('Cust');
        $map['uid'] = session('uid');
        $count = $cust->where($map)->count();
        $Page = getpage($count, 5); // 实例化分页类 传入总记录数
        $show = $Page->show(); // 分页显示输出
                               // $map['xcrq'] = array(array('egt',date("Y-m-d",strtotime("-1 week"))),array('elt',date("Y-m-d",strtotime("+1 month"))));
        $list = $cust->where($map)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->select();
        $this->assign('list', $list);
        $this->assign('page', $show);
        updateTime();
        $this->display();
    }

    public function gos()
    {
        sess();
        $data['url'] = $_SERVER["PATH_INFO"];
        if (in_array($data, control())) {
            $this->error('你没有权限！');
        }
        $gos = M('Mygo');
        $count = $gos->order("id desc")->count();
        $Page = getpage($count, 5);
        $show = $Page->show();
        $list = $gos->order("id desc")
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->select();
        $this->assign('list', $list);
        $this->assign('page', $show);
        updateTime();
        $this->display();
    }

    public function gosView()
    {
        sess();
        $data['url'] = $_SERVER["PATH_INFO"];
        if (in_array($data, control())) {
            $this->error('你没有权限！');
        }
        $gos = M('Mygo');
        $data = $gos->getByid($_GET['id']);
        $this->assign('Rs', $data);
        $this->display();
    }

    public function inform()
    {
        sess();
        $info = M('Info');
        $count = $info->where(array(
            'juid' => array(
                'like',
                '%' . session(uid) . '%'
            )
        ))->count();
        $Page = getpage($count, 5);
        $show = $Page->show();
        $list = $info->where(array(
            'juid' => array(
                'like',
                '%' . session(uid) . '%'
            )
        ))
            ->order("id desc")
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->select();
        $this->assign('list', $list);
        $this->assign('page', $show);
        updateTime();
        $this->display();
    }

    public function informView()
    {
        sess();
        $info = M('Info');
        $data = $info->getByid($_GET['id']);
        $this->assign('Rs', $data);
        $this->display();
    }

    public function outxls()
    {
        sess();
        $name = $_GET['name'];
        if ($name == 'gos') {
            $model = M('Mygo');
            $list = $model->field('id,kssj,jssj,title,uname,bumen,addtime,updatetime')->select();
            $headArr = array(
                'ID',
                '开始时间',
                '结束时间',
                '去向说明',
                '外出人',
                '所在部门',
                '添加时间',
                '更新时间'
            );
            $filename = '员工去向';
            xlsout($filename, $headArr, $list);
        }
        if ($name == 'inform') {
            $model = M('Info');
            $list = $model->field('id,juname,title,jzrq,uname,addtime,uuname,updatetime')->select();
            $headArr = array(
                'ID',
                '接收人',
                '通知标题',
                '截止日期',
                '发布人',
                '发布时间',
                '最后回复',
                '回复时间'
            );
            $filename = '通知公告';
            xlsout($filename, $headArr, $list);
        }
        if ($name == 'myCust') {
            $model = M('Cust');
            $list = $model->field('id,fenlei,title,xcrq,xingming,phone,qq,type,uname,addtime,updatetime')->select();
            $headArr = array(
                'ID',
                '进展',
                '公司名称',
                '下次联系',
                '联系人',
                '手机号码',
                'QQ',
                '客户来源',
                '添加人',
                '添加时间',
                '更新时间'
            );
            $filename = '客户管理';
            xlsout($filename, $headArr, $list);
        }
        if ($name == 'myTask') {
            $model = M('Task');
            $list = $model->field('id,juname,kssj,jssj,title,zhuangtai,uname,addtime,uuname')->select();
            $headArr = array(
                'ID',
                '接收人',
                '开始时间',
                '结束时间',
                '任务标题',
                '状态',
                '发布人',
                '发布时间',
                '更新人'
            );
            $filename = '任务管理';
            xlsout($filename, $headArr, $list);
        }
        updateTime();
    }
}